package formater.utility;

import java.net.URL;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import jaxb.Type;

import org.apache.log4j.Logger;

public class XMLObject {
	private static final Logger log = Logger.getLogger(XMLObject.class);

	private Type type;

	/**
	 * @param  
	 * @return the type
	 */
	public Type getType(URL url) {
		// Read file
		if(type == null) {
			try {
				JAXBContext jaxbContext = JAXBContext.newInstance(Type.class);
				Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();

				type = (Type) unmarshaller.unmarshal(url);
			}catch (JAXBException e) {
				log.error(e.getLocalizedMessage(), e);
			}
		}
		return type;
	}

}
